package com.example.foodisimportant.Canteens;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.Spinner;
import android.widget.TextView;

import com.example.foodisimportant.Adapter.SellerListAdapter;
import com.example.foodisimportant.Bean.SellerEntity;
import com.example.foodisimportant.R;

import java.util.ArrayList;

public class Canteens_Activity extends AppCompatActivity {
    private TextView mTvnameofcanteen;
    private ArrayList<SellerEntity> sellerEntityList =new ArrayList<SellerEntity>();
    private RecyclerView mCollectRecyclerView;
    private SellerListAdapter mCollectRecyclerAdapter;
    private ImageButton mBtnBack;
    private Spinner mSpFloor;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_canteens);
        mTvnameofcanteen=findViewById(R.id.nameofcanteen);
        mBtnBack=findViewById(R.id.back2);
        mSpFloor=findViewById(R.id.sp_floor);
        mBtnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        initData();
        initRecyclerView();
        //根据不同的状态显示不同的界面
        int status = this.getIntent().getIntExtra("status",0);
        if(status == 1) {
            String[] floor1 =new String[]{"F1","F2"};
            ArrayAdapter a=new ArrayAdapter(this,android.R.layout.simple_spinner_item,floor1);
            a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            mSpFloor.setAdapter(a);
            mTvnameofcanteen.setText("学一食堂");
        }else if(status == 3) {
            String[] floor3 =new String[]{"F1"};
            ArrayAdapter a=new ArrayAdapter(this,android.R.layout.simple_spinner_item,floor3);
            a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            mSpFloor.setAdapter(a);
            mTvnameofcanteen.setText("学三食堂");
        }else if(status == 4) {
            String[] floor4 =new String[]{"F1","F2"};
            ArrayAdapter a=new ArrayAdapter(this,android.R.layout.simple_spinner_item,floor4);
            a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            mSpFloor.setAdapter(a);
            mTvnameofcanteen.setText("学四食堂");
        }else if(status == 5) {
            String[] floor5 =new String[]{"F1","F2","F3"};
            ArrayAdapter a=new ArrayAdapter(this,android.R.layout.simple_spinner_item,floor5);
            a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            mSpFloor.setAdapter(a);
            mTvnameofcanteen.setText("学五食堂");
        }

    }

    /**
     * 模拟数据
     */
    private void initData(){
        for(int i=0;i<10;i++)
        {
            SellerEntity sellerEntity=new SellerEntity();
            sellerEntity.setSellerName("青椒炒"+i+"个鸡蛋");
            sellerEntity.setSellerPos("一楼"+i+"号窗口");
            sellerEntityList.add(sellerEntity);
        }
    }

    /**
     * 对recycleview进行设置
     */
    private void initRecyclerView(){
        //获取RecyclerView
        mCollectRecyclerView=findViewById(R.id.rv_sellerlist);
        //创建adapter
        mCollectRecyclerAdapter = new SellerListAdapter(Canteens_Activity.this, sellerEntityList);
        //给RecyclerView设置adapter
        mCollectRecyclerView.setAdapter(mCollectRecyclerAdapter);
        //设置layoutManager,可以设置显示效果，是线性布局、grid布局，还是瀑布流布局
        //参数是：上下文、列表方向（横向还是纵向）、是否倒叙
        mCollectRecyclerView.setLayoutManager(new LinearLayoutManager(Canteens_Activity.this,LinearLayoutManager.VERTICAL,false));
        //设置item的分割线
        mCollectRecyclerView.addItemDecoration(new DividerItemDecoration(Canteens_Activity.this,DividerItemDecoration.VERTICAL));
        //RecyclerView中没有item的监听事件，需要自己在适配器中写一个监听事件的接口。参数根据自定义
        mCollectRecyclerAdapter.setOnItemClickListener(new SellerListAdapter.OnItemClickListener() {
            @Override
            public void OnItemClick(View view, SellerEntity data) {
                //此处进行监听事件的业务处理
                Intent intent=new Intent(Canteens_Activity.this, SellerInformationActivity.class);
                startActivity(intent);
            }
        });
    }

}